﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DevExpress.XtraGrid.Views.Grid;
using System.Drawing;
using CoreData;
using Helper;
using ActionServices;
using DevExpress.XtraGrid.Views.Base;

namespace SchoolManagementSystem.Controls
{
    class SetGridColumnColor
    {
        public static void SetColumnColor(GridView gridView1, int rowindex,string Column, object _Model, Color DefaultBack, Color DefaultFore, RowCellCustomDrawEventArgs e)
        {
            if (_Model.GetType() == typeof(Student_FeeActionService))
            {
               
                var order = (long)gridView1.GetRowCellValue(rowindex, "Order"); //3 mau đỏ chưa đóng lun, 2 màu xám đóng thiếu, 1 màu đen quá hạn mà chưa đóng
                var Status = long.Parse(gridView1.GetRowCellValue(rowindex, "Status").ToString()); 
                if (e.Column.FieldName == "ColorStatusExt")
                {
                    if (Status != 0)
                    {
                        if (order == 3)
                        {

                            e.Appearance.BackColor = Color.Red;
                            e.Appearance.ForeColor = Color.White;
                            e.CellValue = "Chưa đóng";

                        }
                        if (order == 2)
                        {

                            e.Appearance.BackColor = Color.Gray;
                            e.Appearance.ForeColor = Color.White;
                            e.CellValue = "Còn thiếu";

                        }
                        if (order == 1)
                        {

                            e.Appearance.BackColor = Color.Black;
                            e.Appearance.ForeColor = Color.White;
                            e.CellValue = "Quá hạn";

                        }
                    }

                }

            }

            if (_Model.GetType() == typeof(StudentActionService))
            {
                if (e.Column.FieldName == "ColorStatusExt")
                {
                    var id = (long)gridView1.GetRowCellValue(rowindex, "Status");

                    var data = (Student_Status)RegisterService.RegisterServices.StudentStatusService.GetByID(id);
                    if (data != null && !String.IsNullOrEmpty(data.ColorText) && data.ColorText != "-1")
                    {
                        e.Appearance.BackColor = Color.FromArgb(ConvertObject.ToInt(data.ColorText));
                        e.Appearance.ForeColor = Color.White;
                    }
                    else
                    {
                        e.Appearance.BackColor = DefaultBack;
                        e.Appearance.ForeColor = DefaultFore;
                    }
                }
            }
            if (_Model.GetType() == typeof(TempStudentActionService))
            {
                if (e.Column.FieldName == "ColorStatusExt")
                {
                    var id = (long)gridView1.GetRowCellValue(rowindex, "Status");

                    var data = (Student_Status)RegisterService.RegisterServices.StudentStatusService.GetByID(id);
                    if (data != null && !String.IsNullOrEmpty(data.ColorText) && data.ColorText != "-1")
                    {
                        e.Appearance.BackColor = Color.FromArgb(ConvertObject.ToInt(data.ColorText));
                        e.Appearance.ForeColor = Color.White;
                    }
                    else
                    {
                        e.Appearance.BackColor = DefaultBack;
                        e.Appearance.ForeColor = DefaultFore;
                    }
                }
            }

        }
    }
}
